package matrices;

import java.util.Random;

public class Testing {
	public static void main(String [] args){
		System.out.println("Testing the matrix classes:");
		int row = randDim() , col = randDim();
		Matrix [] myAMatrices;
		Matrix [] myBMatrices;
		MatrixElement myElly = new ComplexNumber(0,0);
		
		System.out.println("Creating new " + row + " by " + col + " matrices.");
		myAMatrices = new Matrix[]{
				new DenseMatrix(row,col,myElly),
				new SparseMatrix(row,col,myElly)
		};
		myBMatrices = new Matrix[]{
				new DenseMatrix(row,col,myElly),
				new SparseMatrix(row,col,myElly)
		};
		int seedA = 1, seedB = 2;
		fillMatrix(myAMatrices[0], seedA);
		fillMatrix(myBMatrices[0], seedA);
		fillMatrix(myAMatrices[1], seedB);
		fillMatrix(myBMatrices[1], seedB);
		
		
		System.out.println("Printing matrices...");
		
		for(Matrix mat : myAMatrices) System.out.println(mat);
		for(Matrix mat : myBMatrices) System.out.println(mat);
		
		MatrixVariableWrapper a = new MatrixVariableWrapper("A" ,myAMatrices[0]);
		MatrixVariableWrapper b = new MatrixVariableWrapper("B" ,myBMatrices[0]);
		System.out.println(a.add(b));
	}
	
	public static int randDim(){
		return (int)(Math.random() * 7) + 1;//numebr between 1 and 5
	}
	
	public static void fillMatrix(Matrix mat, int seed){
		Random myRand = new Random(seed);
		for(int i = 0 ; i < mat.getRows() ; i++){
			for(int j = 0 ; j < mat.getColumns() ; j++){
				mat.setElementValueAt(i, j, new ComplexNumber( (float)myRand.nextDouble(),(float)myRand.nextDouble()) );
			}
		}
	}
	
	public static boolean checkMatrixElementsMatch(Matrix a, Matrix b){
		System.out.print("\n\nMatrices " + a + "\n and\n " + b);
		boolean match = true;
		if(a.getRows() != b.getRows() || a.getColumns() != b.getColumns()){
			match = false;
			System.out.print(" are not equal\n\n");
			return match;
		}
		for(int i = 0 ; i < a.getRows() ; i ++)
			for(int j = 0; j < a.getColumns() ; j++)
				if(
					!	a.getElementValueAt(i, j).isEqualTo(b.getElementValueAt(i,j))
						) match = false;
		if(match){
			System.out.print(" are equal\n\n");
		}else{
			System.out.print(" are not equal\n\n");
		}
		return match;
	}
}
